package tv.youxing.android.ui;
/**
 * Created by apple on 2017/4/24.
 */

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.kymjs.rxvolley.RxVolley;
import com.kymjs.rxvolley.client.HttpCallback;
import com.kymjs.rxvolley.client.HttpParams;
import com.kymjs.rxvolley.http.VolleyError;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import tv.youxing.android.R;
import tv.youxing.android.custom.CustomToast;
import tv.youxing.android.entity.PhoneCodeModel;
import tv.youxing.android.utils.GsonUtils;
import tv.youxing.android.utils.L;
import tv.youxing.android.utils.StaticClass;
import tv.youxing.android.utils.UtilTools;

/**
 * 项目名：   youxing
 * 包名：     tv.youxing.android .ui
 * 文件名：   ForgetPasswordActivity
 * 创建者：   叶克武
 * 创建时间： 2017/4/24 下午7:31
 * 描述：    TODO
 */
public class ForgetPasswordActivity extends BaseActivity {


    @BindView(R.id.phone)
    EditText ed_phone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_forget_password);
        ButterKnife.bind(this);
    }


    @OnClick(R.id.btn_getCheckCode)
    public void onViewClicked(View view) {

        switch (view.getId()) {
            case R.id.btn_getCheckCode:

            sendCode();

                break;
        }

    }

    void sendCode() {
        final String phone = UtilTools.getString(ed_phone);

        if (!UtilTools.isPhoneSuccess(phone)||phone.length()<=0) {
            CustomToast.INSTANCE.showToast("手机号码格式不正确");
            return;
        }



        HttpParams params = new HttpParams();
        params.put("mobile", phone);

        RxVolley.post(StaticClass.sendCheckCodeURL, params, new HttpCallback() {
            @Override
            public void onSuccess(String t) {


                PhoneCodeModel pd = GsonUtils.GsonToBean(t, PhoneCodeModel.class);

                if (pd.getCode() == 200) {
                    CustomToast.INSTANCE.showToast(pd.getStatus());

//                    Intent intent = new Intent(ForgetPasswordActivity.this, CheckCodeActivity.class);
                    Intent intent = new Intent(ForgetPasswordActivity.this, SetPasswordActivity.class);
                    intent.putExtra("phone",phone);
                    startActivity(intent);

                }else{
                    CustomToast.INSTANCE.showToast("error:" + pd.getCode() + "---" + pd.getStatus());
                }
            }

            @Override
            public void onFailure(VolleyError error) {
                super.onFailure(error);
                L.d("errorCode:" + error.getMessage());
            }
        });
    }


}
